$package('itsm.system');

itsm.system.staticHongMain=function(){
	this.opt='';
	return {
		//列表
		staticHongMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'trans!findTransactionRecordPager.action',
				postData:{'trDTO.transactionType':'RiFenHong'},
				caption:'静态分红',
				colNames:['ID','会员ID','对象','类型','收入','支出','余额','操作时间','备注'],
			 	colModel:[
			 	          {name:'recordId',align:'center'},
			 	          {name:'loginName',align:'center'},
			 	          {name:'transactionObject',align:'center'},
			 	          {name:'transactionType',align:'center',formatter:i18nForma},
			 	          {name:'income',align:'center'},
			 	          {name:'expenditure',align:'center'},
			 	          {name:'balance',align:'center'},
			 	         {name:'optDate',align:'center',formatter:timeFormatter},
			 	          {name:'remark',align:'center'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "recordId"}),
				sortname:'recordId',
				pager:'#staticHongMainPager'
				});
				$("#staticHongMainGrid").jqGrid(params);
				$("#staticHongMainGrid").navGrid('#staticHongMainPager',navGridParams);
				//列表操作项
				$("#t_staticHongMainGrid").css(jqGridTopStyles);
				$("#t_staticHongMainGrid").html($('#staticHongMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#staticHongMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveRule';
			resetForm('#staticHongMain_add_form');
			$('#staticHongMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editRule';
			checkBeforeEditGrid('#staticHongMainGrid',function(rowData){
				$.post('trans!findRuleByRuleCode.action','ruleDTO.ruleCode='+rowData.ruleCode,function(data){
					$('#staticHongMain_ruleId').val(data.ruleId);
					$('#staticHongMain_ruleName').val(data.ruleName);
					$('#staticHongMain_ruleCode').val(data.ruleCode);
					$('#staticHongMain_ruleValue').val(data.ruleValue);
				});
				$('#staticHongMain_add_win').window('open');
			});	
		},
		
		//保存
		savestaticHong:function(){
			if($('#staticHongMain_add_win').form('validate')){
				var _param = $('#staticHongMain_add_win form').serialize();
				$.post('trans!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#staticHongMain_add_win').window('close');
					$('#staticHongMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		//删除
		deleteTrans:function(){
			checkBeforeDeleteGrid('#staticHongMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("trans!deleteTrans.action", pp, function(){
					$('#staticHongMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#staticHongMain_search_win').window('open');
		},
		//搜索
		searchstaticHong:function(){
			var sdata=$('#staticHongMain_search_win form').getForm();
			var postData = $("#staticHongMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'trans!findTransactionRecordPager.action';		
			$('#staticHongMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		everyDayHong:function(){
			var rows = 200;
			$("#everyDayHongBut1").attr({"disabled":"disabled"});
			var tongtao = $('#userQuy').val();
			var serverUrl1 = $('#serverUrl1').val();
			var serverUrl2 = $('#serverUrl2').val();
			var serverUrl='';
			$('#hongStatus1').html("正在计算中，请稍候......");
			for(var i=0;i<tongtao;i++){
				if(i%2==0){
					serverUrl=serverUrl1;
				}else{
					serverUrl=serverUrl2;
				}
				
				$.post(serverUrl+'?page='+(i+1)+'&rows='+rows,function(result){
					//alert(result);
					//$('#hongStatus').text(result);
					//$('#staticHongMainGrid').trigger('reloadGrid');
					//$("#everyDayHongBut").removeAttr("disabled");
					$('#hongStatus1').append("<br>"+result);
				})
			}
			
			
//			if(confirm('确定要计算日分红吗?')){
//				
//			}
		},
		everyDayHong1:function(){
			if(confirm('确定要发放日分红吗?')){
				$("#everyDayHongBut1").attr({"disabled":"disabled"});
				$('#hongStatus').text("正在发放中，请稍候......");
				$.post('bonus!everyDayHong.action',function(result){
					alert(result);
					$('#hongStatus').text(result);
					$('#staticHongMainGrid').trigger('reloadGrid');
					$("#everyDayHongBut1").removeAttr("disabled");
				})
			}
		},
		init:function(){
			itsm.system.staticHongMain.staticHongMainGrid();
		}
	}
	
}();

$(function(){
	itsm.system.staticHongMain.init();
});